Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.Configuration
Imports System.Data.SqlClient
Imports System.Data

Public Partial Class MovieTixStaff_AddTheatre
	Inherits System.Web.UI.Page
	Protected Sub Page_Load(sender As Object, e As EventArgs)

    End Sub
    Protected Sub function1(ByVal sender As Object, ByVal e As EventArgs)
        Dim tb2 As TextBox = DirectCast(frmAddTheatre.FindControl("txtTheatreName"), TextBox)

        Label1.Text = tb2.Text


    End Sub
    Protected Sub clearall(ByVal sender As Object, ByVal e As EventArgs)
        Label1.Text = ""

    End Sub
    Protected Sub function2(ByVal source As Object, ByVal args As ServerValidateEventArgs)

        Dim tb2 As TextBox = DirectCast(frmAddTheatre.FindControl("txtTheatreName"), TextBox)

        Dim tb3 As LinkButton = DirectCast(frmAddTheatre.FindControl("lnkInsert"), LinkButton)
        Dim connectionString As String
        connectionString = WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        Dim con As New SqlConnection(connectionString)
        Dim cmd1 As New SqlCommand("SELECT *  from Theatre WHERE Theatrename=@Theatrename", con)

        Dim Showing As [Boolean]
        cmd1.Parameters.AddWithValue("@Theatrename", tb2.Text)
        Using con
            con.Open()
            Dim reader As SqlDataReader = cmd1.ExecuteReader()
            If reader.HasRows Then
                Label7.Text = ""
                args.IsValid = False



                Label1.Text = "This theatre name " + tb2.Text + " already exist, please try another name!"
            Else
                Label1.Text = ""
                UpdatePanel2.Update()
                args.IsValid = True
                Label7.Text = "A new theare is added successfully! "



                tb3.CommandName = "insert"
            End If
        End Using

    End Sub
    Protected Sub function3(ByVal source As Object, ByVal e As EventArgs)

        Dim tb2 As TextBox = DirectCast(frmAddTheatre.FindControl("txtTheatreName"), TextBox)

        Dim tb3 As LinkButton = DirectCast(frmAddTheatre.FindControl("lnkInsert"), LinkButton)
        Dim connectionString As String
        connectionString = WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        Dim con As New SqlConnection(connectionString)
        Dim cmd1 As New SqlCommand("SELECT *  from Theatre WHERE Theatrename=@Theatrename", con)

        Dim Showing As [Boolean]
        cmd1.Parameters.AddWithValue("@Theatrename", tb2.Text)
        Using con
            con.Open()
            Dim reader As SqlDataReader = cmd1.ExecuteReader()
            If reader.HasRows Then

                Label1.Text = "This theatre name: " + tb2.Text + " already exist, please try another name!"


                tb3.CommandName = ""
            Else

                UpdatePanel2.Update()
                Label7.Text = "A new theare is added successfully! "



                tb3.CommandName = "insert"
            End If
        End Using

    End Sub

    Protected Sub test4(ByVal source As Object, ByVal e As EventArgs)
        UpdatePanel2.Update()

    End Sub
    Protected Sub menuTabs_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs)
        multiTabs.ActiveViewIndex = Int32.Parse(menuTabs.SelectedValue)
        Label7.Text = ""
        Label1.Text = ""
        UpdatePanel2.Update()

    End Sub

End Class
